package com.example;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;

import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.nio.file.Paths;


public class MyBatisPlusCodeGeneration {
    public static void main(String[] args) {
        FastAutoGenerator.create("jdbc:mysql://localhost:3306/test", "root", "123456")
                .globalConfig(builder -> builder//公共配置
                        .author("xiaozhang")
                        .outputDir(Paths.get(System.getProperty("user.dir")) + "/src/main/java")
                        .commentDate("yyyy-MM-dd HH:mm")
                )
                .packageConfig(builder -> builder//包管理
                        .parent("com.example")
                        .entity("entity")
                        .mapper("mapper")
                        .service("service")
                        .serviceImpl("service.impl")
                        .xml("mapper.xml")
                        .controller("controller")
                )
                .strategyConfig(builder -> builder
                        .addInclude("emp","dept")//表
                        .entityBuilder()
                        .enableLombok()
                        .controllerBuilder()//生成controller
                        .enableRestStyle()//添加RestController注解
                        .enableHyphenStyle()//如果表名是驼峰，则转为中划线连接
                )
                .templateEngine(new FreemarkerTemplateEngine())
                .execute();
    }
}
